home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 11 / CU Amiga Magazine's Super CD-ROM 11 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-06].iso / cucd / programming / oberonv4 / source / system / make.mod (.txt) < prev    next >
Oberon Text  |  1994-10-18  |  6KB  |  136 lines

  1. Syntax10.Scn.Fnt
  2. Syntax10i.Scn.Fnt
  3. StampElems
  4. Alloc
  5. 24 Feb 94
  6. Courier10.Scn.Fnt
  7. Syntax10b.Scn.Fnt
  8. MODULE Make;    (** SHML 8 Sep 92, 
  9.     IMPORT Texts, TF := TextFrames, Viewers, MV := MenuViewers, Oberon, Log;
  10.     CONST
  11.         Debug = FALSE;
  12.         defaultCompiler = "Compiler.Compile"; optionChar = "/"; defaultOptions = "s";
  13.         null = 0; ident = 1; semicolon = 2; becomes = 3;
  14.     TYPE Table = ARRAY 128, 32 OF CHAR;
  15.     VAR W: Texts.Writer; ch: CHAR;
  16.     PROCEDURE Scan(VAR r: Texts.Reader; VAR name: ARRAY OF CHAR; VAR sym: INTEGER);
  17.         PROCEDURE Identifier;
  18.             VAR i: INTEGER;
  19.         BEGIN
  20.             i := 0;
  21.             REPEAT name[i] := ch; INC(i); Texts.Read(r, ch)
  22.             UNTIL (ch < "0") OR ("9" < ch) & (CAP(ch) < "A") OR ("Z" < CAP(ch)) OR (i = LEN(name));
  23.             IF i = LEN(name) THEN DEC(i); sym := null ELSE sym := ident END;
  24.             name[i] := 0X
  25.         END Identifier;
  26.         PROCEDURE Comment;    (* do not read after end of file *)
  27.         BEGIN
  28.             Texts.Read(r, ch);
  29.             LOOP
  30.                 LOOP
  31.                     WHILE ch = "(" DO Texts.Read(r, ch); IF ch = "*" THEN Comment END END;
  32.                     IF ch = "*" THEN Texts.Read(r, ch); EXIT END;
  33.                     IF r.eot THEN EXIT END;
  34.                     Texts.Read(r, ch)
  35.                 END;
  36.                 IF ch = ")" THEN Texts.Read(r, ch); EXIT END;
  37.                 IF r.eot THEN EXIT END
  38.             END
  39.         END Comment;
  40.     BEGIN
  41.         WHILE ch <= " " DO    (* ignore control characters *)
  42.             IF r.eot THEN RETURN ELSE Texts.Read(r, ch) END
  43.         END;
  44.         CASE ch OF    (* ch > " " *)
  45.             | "(": Texts.Read(r, ch); IF ch = "*" THEN Comment; Scan(r, name, sym) END
  46.             | ":": Texts.Read(r, ch); IF ch = "=" THEN Texts.Read(r, ch); sym := becomes ELSE sym := null END
  47.             | ";": sym := semicolon; Texts.Read(r, ch)
  48.             | "A".."Z", "a".."z": Identifier
  49.         ELSE Texts.Read(r, ch); sym := null
  50.         END;
  51.     END Scan;
  52.     PROCEDURE Imports(VAR list: Table; VAR max: INTEGER; name: ARRAY OF CHAR; short: BOOLEAN);
  53.         VAR T: Texts.Text; r: Texts.Reader; source, import, s: ARRAY 32 OF CHAR; this, i, j, sym: INTEGER;
  54.     BEGIN
  55.         IF (name = "SYSTEM") OR short & ((name = "Display") OR (name = "FileDir") OR (name = "Files")
  56.                 OR (name = "Fonts") OR (name = "Input") OR (name = "Kernel") OR (name = "MenuViewers")
  57.                 OR (name = "Modules") OR (name = "Oberon") OR (name = "Printer") OR (name = "Reals")
  58.                 OR (name = "TextFrames") OR (name = "Texts") OR (name = "Viewers") OR (name = "WriteFrames")
  59.                 OR (name = "WritePrinter")) THEN
  60.             RETURN
  61.         END;
  62.         i := -1; REPEAT INC(i); source[i] := name[i] UNTIL name[i] = 0X;
  63.         source[i] := "."; source[i+1] := "M"; source[i+2] := "o"; source[i+3] := "d"; source[i+4] := 0X;
  64.         T := TF.Text(source);
  65.         IF T.len = 0 THEN name[i] := "-"; name[i+1] := 0X END;
  66.         (* append name to list, if not already there *)
  67.         i := 0; WHILE (i < max) & (name # list[i]) DO INC(i) END;
  68.         IF i < max THEN RETURN    (* was processed already *)
  69.         ELSE COPY(name, list[max]); this := max; INC(max)
  70.         END;
  71. IF Debug THEN Log.Str("inserting "); Log.Str(name); Log.Ln END;
  72.         Texts.OpenReader(r, T, 0); ch := " ";
  73.         REPEAT Scan(r, s, sym) UNTIL r.eot OR (sym = ident) & (s = "IMPORT");
  74.         IF r.eot THEN RETURN END;
  75.         LOOP
  76.             Scan(r, s, sym);
  77.             IF r.eot THEN EXIT END;
  78.             COPY(s, import); Scan(r, s, sym);
  79.             IF r.eot THEN EXIT END;
  80.             IF sym = becomes THEN Scan(r, s, sym); COPY(s, import); Scan(r, s, sym) END;
  81.             IF r.eot THEN EXIT END;
  82.             (* search import in list *)
  83.             i := 0; WHILE (i < this) & (import # list[i]) DO INC(i) END;
  84.             IF i < this THEN    (* was imported already by another module -> move name (@ this) before import (@ i) *)
  85. IF Debug THEN Log.Str("moving "); Log.Str(name); Log.Int(this); Log.Str(" before "); Log.Str(import); Log.Int(i); Log.Ln END;
  86.                 j := this; WHILE j > i DO list[j] := list[j-1]; DEC(j) END;
  87.                 COPY(name, list[i]); this := i
  88.             END;
  89.             Imports(list, max, import, short);
  90.             IF r.eot OR (sym = semicolon) THEN EXIT END
  91.         END
  92.     END Imports;
  93.     PROCEDURE MakeList(short: BOOLEAN);
  94.         CONST Menu = "System.Close  System.Copy  System.Grow  Edit.Search  Edit.Replace All  Edit.Store ";
  95.         VAR
  96.             V: Viewers.Viewer; T: Texts.Text; S: Texts.Scanner;
  97.             beg, end, time: LONGINT;
  98.             imports: Table;
  99.             max, x, y, i: INTEGER;
  100.             opt: ARRAY 32 OF CHAR;
  101.     BEGIN
  102.         Texts.OpenScanner(S, Oberon.Par.text, Oberon.Par.pos); Texts.Scan(S);
  103.         IF (S.class = Texts.String) & (S.line = 0) THEN COPY(S.s, opt); Texts.Scan(S) ELSE opt := defaultOptions END;
  104.         IF (S.class = Texts.Char) & (S.line = 0) & (S.c = "^") THEN
  105.             Oberon.GetSelection(T, beg, end, time);
  106.             IF time >= 0 THEN Texts.OpenScanner(S, T, beg); Texts.Scan(S) END
  107.         END;
  108.         IF S.class = Texts.Name THEN
  109.             i := S.len;
  110.             IF (i >= 6) & (S.s[i-4] = ".") & (S.s[i-3] = "M") & (S.s[i-2] = "o") & (S.s[i-1] = "d") THEN S.s[i-4] := 0X END;
  111.             max := 0; Imports(imports, max, S.s, short);
  112.             IF max > 0 THEN
  113.                 Oberon.AllocateUserViewer(Oberon.Mouse.X, x, y); T := TF.Text("");
  114.                 V := MV.New(TF.NewMenu(S.s, Menu), TF.NewText(T, 0), TF.menuH, x, y);
  115.                 Texts.WriteString(W, defaultCompiler); Texts.WriteLn(W);
  116.                 REPEAT
  117.                     DEC(max);
  118.                     Texts.WriteString(W, imports[max]); Texts.WriteString(W, ".Mod");
  119.                     IF opt[0] # 0X THEN Texts.Write(W, optionChar); Texts.WriteString(W, opt) END;
  120.                     Texts.WriteLn(W)
  121.                 UNTIL max = 0;
  122.                 Texts.Write(W, "~"); Texts.WriteLn(W); Texts.Append(T, W.buf)
  123.             END
  124.         END
  125.     END MakeList;
  126.     PROCEDURE Make*;
  127.     (** (name options) | "^"     generate compile list of module name with /options appended to it **)
  128.     BEGIN MakeList(TRUE)
  129.     END Make;
  130.     PROCEDURE MakeLong*;
  131.     (** (name options) | "^"     generate compile list including core modules of module name with /options appended to it **)
  132.     BEGIN MakeList(FALSE)
  133.     END MakeLong;
  134. BEGIN Texts.OpenWriter(W)
  135. END Make.
  136.